<?php
if ($stat != 1) {
    ?>

    <script>
                                
        function cari_biaya(){
            var id_mitra = $('input:radio[name=mitra]:checked').val();
            var id_kota=$("#kota2").val();
                                                  
            var link="";
            if(id_kota==""){
                link=base_url+"main/keranjang/res_total_biaya/";
            }
            else{
                link=base_url+"main/keranjang/total_biaya/"+id_kota+"/"+id_mitra;
            }
            var dataString="";
            $.ajax({
                type: "POST",
                                                                
                url: link,
                data: dataString,
                cache: false,
                success: function(html){
                    $(".biaya").html(html);
                } 
            });
        }
                                
                                
                                
        $(document).ready(function(){
            $("#kota2").change(function(){
                                                
                cari_biaya();
                                                
            });
                                                
            $(".mitra").click(function(){
                var id_mitra = $('input:radio[name=mitra]:checked').val();
                var id_kota=$("#kota2").val();
                var link=base_url+"main/keranjang/total_biaya/"+id_kota+"/"+id_mitra;
                if(id_kota!=""){
                    var dataString="";
                    $.ajax({
                        type: "POST",
                                                                
                        url: link,
                        data: dataString,
                        cache: false,
                        success: function(html){
                            $(".biaya").html(html);
                        } 
                    });               
                }
                                                    
            });        
                                                
                                                
            $('#samakan').click(function() {
                var x=$('#samakan:checkbox:checked').val();
                if(x=="samakan"){
                    $('#nama_depan2').val($('#nama_depan').val());
                    $('#nama_belakang2').val($('#nama_belakang').val());
                    $('#alamat2').val($('#alamat').val());
                    $('#kode_pos2').val($('#kode_pos').val());
                    $('#telp2').val($('#telp').val());
                                                    
                    $('#provinsi2').val($('#provinsi').val());
                                                    
                    var id_prov=$('#provinsi').val();
                    var id_kota=$('#kota').val();
                                            
                    var dataString="";
                    $.ajax({
                        type: "POST",
                                                    
                        url: base_url+"index.php/admin_kota/data_kota/"+id_prov+"/"+id_kota,
                        data: dataString,
                        cache: false,
                        success: function(html){
                            $("#kota2").html(html);
                            cari_biaya();
                        } 
                    });
                                            
                }  
                else{
                    $('#nama_depan2').val("");
                    $('#nama_belakang2').val("");
                    $('#alamat2').val("");
                    $('#kode_pos2').val("");
                    $('#telp2').val("");
                    $('#provinsi2').val("");
                    $("#kota2").html("<option value=''>Pilih Kota :</option>");
                                    
                    cari_biaya();
                }
            });
                                                
        });
                                            
    </script>

    <div class="member sixteen columns">

        <?php
        $atr = array('id' => 'formID',
            'class' => 'formular');
        echo form_open('main/pembayaran/save_transaksi/', $atr);
        ?> 
        <div class="eight columns alpha ">
            <div class="box_head">
                <h3>Alamat Pemesanan</h3>
            </div>
            <p> <span> Nama Depan </span> <input type="text" size="30" name="nama_depan" id="nama_depan"  value="<?php echo $list_member->nama_depan ?>" class="validate[required] text-input"/>   </p>
            <p> <span> Nama Belakang </span> <input type="text" size="30" name="nama_belakang" id="nama_belakang"  value="<?php echo $list_member->nama_belakang ?>" class="validate[required] text-input"/>   </p>
            <p> <span> Provinsi </span> 
                <select name="provinsi" id="provinsi" class="validate[required] text-input"/>
            <option value=''>Pilih Provinsi : </option>
            <?php
            foreach ($list_prov as $dtprov) {
                if ($dtprov->id == $list_member->id_provinsi)
                    $sel = "selected";
                else
                    $sel = "";
                echo "<option value='$dtprov->id' $sel>$dtprov->nama_provinsi</option>";
            }
            ?> 
            </select>
            </p>
            <p> <span> Kota</span> 
                <select name="kota" id="kota" class="validate[required] text-input"/> 
            <option value=''>Pilih Kota : </option>
            <?php
            foreach ($list_kota as $dt_kota) {
                if ($dt_kota->id == $list_member->id_kota)
                    $sel = "selected";
                else
                    $sel = "";
                echo "<option value='$dt_kota->id' $sel>$dt_kota->nama_kota</option>";
            }
            ?> 
            </select>        

            </p>
            <p> <span> Alamat</span> <input type="text" size="45" name="alamat" id="alamat"  value="<?php echo $list_member->alamat ?>" class="validate[required] text-input"/>   </p>
            <p> <span> Kode Pos</span> <input type="text" name="kode_pos" id="kode_pos"  value="<?php echo $list_member->kode_pos ?>" class="validate[required] text-input"/>   </p>
            <p> <span> Telp</span> <input type="text" name="telp" id="telp"  value="<?php echo $list_member->telp ?>" class="validate[required] text-input"/>   </p>

        </div>

        <div class="eight columns omega  ">
            <div class="box_head">
                <h3>Alamat Pengiriman</h3>
            </div>
            <p> <span> Nama Depan </span> <input type="text" size="30" id="nama_depan2" name="nama_depan2" class="validate[required] text-input"/>   </p>
            <p> <span> Nama Belakang </span> <input type="text" size="30" id="nama_belakang2" name="nama_belakang2" class="validate[required] text-input"/>   </p>
            <p> <span> Provinsi </span> 
                <select name="provinsi2" id="provinsi2" class="validate[required] text-input"/>
            <option value=''>Pilih Provinsi : </option>
            <?php
            foreach ($list_prov as $dtprov) {
                echo "<option value='$dtprov->id' >$dtprov->nama_provinsi</option>";
            }
            ?> 
            </select>
            </p>
            <p> <span> Kota</span> 
                <select name="kota2" id="kota2" class="validate[required] text-input"/>
            <option value=''>Pilih Kota : </option>
            </select>
            </p>
            <p> <span> Alamat</span> <input type="text" size="45" name="alamat2" id="alamat2" class="validate[required] text-input"/>   </p>
            <p> <span> Kode Pos</span> <input type="text" name="kode_pos2" id="kode_pos2" class="validate[required] text-input"/>   </p>
            <p> <span> Telp</span> <input type="text" name="telp2" id="telp2" class="validate[required] text-input"/>   </p>
            <p> <label><input type="checkbox" id="samakan" value="samakan"/> Samakan dengan alamat pemesan </label> </p>
        </div>
        <div class="clear"></div>
        <br/>

        <div class="sixteen columns alpha">
            <div class="box_head">
                <h3>PEMBAYARAN</h3>
            </div>
            <p style="line-height: 35px;"> Silahkan pilih jasa pengiriman beserta cara pembayaran sesuai kenginan anda. </p>
            <p>
                <b> &nbsp; &nbsp; &nbsp; Jasa Pengiriman </b> <br/>
                <?php
                $n = 1;
                foreach ($list_mitra as $dtmitra) {
                    echo "<label>";
                    echo "&nbsp; &nbsp; &nbsp;";
                    if ($n == 1)
                        $sel = "checked";
                    else
                        $sel = "";
                    echo "<input type='radio' name='mitra' id='$dtmitra->id' class='mitra' value='$dtmitra->id' $sel />";
                    echo "$dtmitra->nama_mitra ";
                    echo "</label>";
                    $n++;
                }
                ?>



            </p> 
            <p>
                <b> &nbsp; &nbsp; &nbsp; Jenis Pembayaran </b> <br/>

                <label>
                    &nbsp; &nbsp; &nbsp;
                    <input type="radio" name="pembayaran"  id="pembayaran" value="transfer" checked />
                    Transfer Bank
                </label>
                <label>
                    &nbsp; &nbsp; &nbsp;
                    <input type="radio" name="pembayaran" id="pembayaran" value="paypal"  />
                    Paypal Payment
                </label>
            </p> 
            <p>
                <b> &nbsp; &nbsp; Komentar seputar pemesanan anda </b> <br/>

                <label>
                    &nbsp; &nbsp; &nbsp;
                    <textarea class="eight columns" rows="4"  id="komentar" name="komentar"></textarea>

                </label>


            </p> <br/>

            <?php
            $lib_rupiah = new Format_rupiah();
            $item = 0;
            $grand = 0;
            foreach ($keranjang as $dta) {
                $harga = $dta['price'];
                $bnyk = $dta['qty'];
                $diskon = $dta['options']['disc'];

                $sub = ($harga * $bnyk) - ($harga * $bnyk) * $diskon / 100;
                $grand = $sub + $grand;
                $item++;
            }
            ?><div class="clear"></div>  <br/>
            <table >
                <tr>
                    <th> BIAYA PEMESANAN </th>
                    <th> &nbsp;</th>
                    <th> BIAYA PENGIRIMAN </th>
                    <th> &nbsp; </th>
                    <th> GRAND TOTAL </th>
                </tr>
                <tr class="biaya" >
                    <td> <p> <?php echo $item; ?> Item Produk <br/> <?php echo $lib_rupiah->rupiah($grand); ?> </p> </td>
                    <td> + </td>
                    <td> <p> - <br/> Rp. 0 <p> </td>
                    <td> = </td>
                    <td> <p>Jumlah Biaya Pemesanan <br/> <?php echo $lib_rupiah->rupiah($grand); ?></p> </td>
                </tr>

            </table>
            <br/>

            <?php echo anchor("main/keranjang/", "Kembali", "class='red_btn'") ?>
            <input type="submit" value="Check Out Pemesanan" class="red_btn"/>
            <br/><br/>
            </form>
        </div>

    </div>

    <div class="clear"></div>  


    </div>

    <?php
} else {
    ?>

    <div id="alert">
        <p><b>Terima kasih,,, <br/> Pemesanan anda telah kami simpan, silahkan melakukan pembayaran secepat'ya. !!!</b></p>
    </div>
    <?php
}
?>